<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--<%@page import="com.oracle.xiaomi.pojo.*" %>--%>
<%@page import="java.util.*" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script type="text/javascript">
        if ("${del}" != "") {
            alert("${del}");
        }
    </script>
    <c:remove var="del"></c:remove>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bright.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/addBook.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#selectAll").click(function(){
                $("[name=\"ids\"]").prop("checked",$(this).prop("checked"));
            });
        });
    </script>
    <title></title>
</head>

<body>
<div id="brall">
    <div id="nav">
        <p>商品管理>商品列表 回显</p>
    </div>
    <div id="condition" style="text-align: center">
        <form id="myform" action="${pageContext.servletContext.contextPath}/prod/mySplict.action" method="post">
            商品名称：<input name="pname" id="pname" value="${sessionScope.productvo.pname}">&nbsp;&nbsp;&nbsp;
            商品类型：<select name="typeid" id="typeid">
            <option value="-1">请选择</option>
            <c:forEach items="${sessionScope.ptlist}" var="pt">
                <option  value="${pt.typeId}" ${pt.typeId==sessionScope.productvo.typeid ? "selected":""} >
                        ${pt.typeName}
                </option>
            </c:forEach>
        </select>&nbsp;&nbsp;&nbsp;
            价格：<input name="lprice" id="lprice" value="${sessionScope.productvo.lprice}">-
            <input name="hprice" id="hprice" value="${sessionScope.productvo.hprice}">
            <input type="submit" value="查询" />
        </form>
    </div>
    <br>
    <div id="table">
        <c:choose>
            <c:when test="${pb.list.size()!=0}">

                <div id="top">
                    <a href="${pageContext.request.contextPath}/admin/addproduct.jsp?page=${pb.pageNum}">
                            <%--<input type="button" class="btn btn-warning"  id="btn1" data-toggle="modal" data-target="#myModal"--%>
                            <%--value="新增商品">--%>
                        <input type="button" class="btn btn-warning" id="btn1"
                               value="新增商品">
                    </a>
                </div>
                <!--显示分页后的商品-->
                <form action="${pageContext.request.contextPath}/prod/batchDel.action" method="post">
                    <input type="checkbox" id="selectAll"/>全选
                    <input type="submit" value="批量删除"/>




                <div id="middle">
                    <table class="table table-bordered table-striped">
                        <tr>

                            <th>ID</th>
                            <th>商品名</th>
                            <th>商品介绍</th>
                            <th>定价（元）</th>
                            <th>商品图片</th>
                            <th>商品数量</th>

                            <th>操作</th>
                        </tr>

                        <c:forEach items="${pb.list}" var="p">
                            <tr>
                                <td>
                                    <input type="checkbox" name="ids" value="${p.pId}"/>
                                </td>
                                <td>${p.pName}</td>
                                <td>${p.pContent}</td>
                                <td>${p.pPrice}</td>
                                <td><img width="55px" height="45px"
                                         src="${pageContext.request.contextPath}/image_big/${p.pImage}"></td>
                                <td>${p.pNumber}</td>
                                    <%--<td><a href="${pageContext.request.contextPath}/admin/product?flag=delete&pid=${p.pId}" onclick="return confirm('确定删除吗？')">删除</a>--%>
                                    <%--&nbsp;&nbsp;&nbsp;<a href="${pageContext.request.contextPath}/admin/product?flag=one&pid=${p.pId}">修改</a></td>--%>

                                <td>
                                    <button type="button" class="btn btn-info myupdate"
                                            onclick="one(${p.pId},${pb.pageNum})">编辑
                                    </button>
                                    <button type="button" class="btn btn-warning" id="mydel"
                                            onclick="del(${p.pId},${pb.pageNum})">删除
                                    </button>

                                </td>
                            </tr>
                        </c:forEach>
                    </table>

                    <!--分页栏-->
                    <div id="bottom">
                        <ul class="pagination">
                            <li>
                                <a href="#">[总共页${pb.pages}]/[当前${pb.pageNum}]</a>
                            </li>
                            <li>
                                <a href="${pageContext.servletContext.contextPath}/prod/mySplict.action?page=1&pname=${sessionScope.productvo.pname}&typeid=${sessionScope.productvo.typeid}&lprice=${sessionScope.productvo.lprice}&hprice=${sessionScope.productvo.hprice}">首页</a>
                            </li>
                            <li>
                                <a href="${pageContext.servletContext.contextPath}/prod/mySplict.action?page=${pb.prePage}&pname=${sessionScope.productvo.pname}&typeid=${sessionScope.productvo.typeid}&lprice=${sessionScope.productvo.lprice}&hprice=${sessionScope.productvo.hprice}">上一页</a>
                            </li>
                            <li>
                                <a href="${pageContext.servletContext.contextPath}/prod/mySplict.action?page=${pb.nextPage}&pname=${sessionScope.productvo.pname}&typeid=${sessionScope.productvo.typeid}&lprice=${sessionScope.productvo.lprice}&hprice=${sessionScope.productvo.hprice}">下一页</a>
                            </li>
                            <li>
                                <a href="${pageContext.servletContext.contextPath}/prod/mySplict.action?page=${pb.pages}&pname=${sessionScope.productvo.pname}&typeid=${sessionScope.productvo.typeid}&lprice=${sessionScope.productvo.lprice}&hprice=${sessionScope.productvo.hprice}">尾页</a>
                            </li>
                    </div>
                </div>
                </form>
            </c:when>
            <c:otherwise>
                <div>
                    <h2 style="width:1200px; text-align: center;color: orangered;margin-top: 100px">暂时没有符合条件的商品！</h2>
                </div>
            </c:otherwise>
        </c:choose>
    </div>


</div>
</body>
<!--弹出新增模式对话框-->
<script type="text/javascript">
    $(function () {
        $(".btn-info").on("click", function () {
            //浏览不关，第二次打开时要清空
            $("#myModal").modal("hide");

        });
        //新增学生非空判断
        $(".btn-success").on("click", function () {
            $("#myModal").modal("hide");
        });
    });
</script>
<script type="text/javascript">
    function mysubmit() {
        $("#myform").submit();
    }
    function del(pid,ispage) {
        if (confirm("确定删除吗")) {
            location.href = "${pageContext.request.contextPath}/prod/delete.action?pid="+pid+"&ispage="+ispage;
        }
    }

    function one(pid,ispage) {
        location.href = "${pageContext.request.contextPath}/prod/one.action?pid="+pid+"&ispage="+ispage;
    }
</script>
<!--分页的AJAX实现-->
<script type="text/javascript">
    function split(page) {

        //取出所有的条件
        var pname=$("#pname").val();
        var typeid=$("#typeid").val();
        var lprice=$("#lprice").val();
        var hprice=$("#hprice").val();

        $.ajax({
            type: "post",
            url: "${pageContext.request.contextPath}/prod/ajaxSplit.action",
            data: { "page": page,"pname":pname,"typeid":typeid,"lprice":lprice,"hprice":hprice},
            success: function () {


                $("#table").load("http://localhost:8080/admin/product.jsp #table")
            },
            error: function (e) {
                alert(e.message);
            }
        });
    }
</script>

</html>